package com.itheima.d2_xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/*
  目标：如何使用程序把数据写出到 XML文件中去。

  <?xml version="1.0" encoding="UTF-8" ?>
  <book>
      <name>从入门到跑路</name>
      <author>xxxx</author>
      <price>999.9</price>
  </book>
 */
public class Dom4JTest2 {
    public static void main(String[] args) throws DocumentException {
        // TODO 将注释中的xml内容写到文件book.xml文件中
        //使用一个StringBuilder对象来拼接XML格式的数据。
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(" <?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
                "  <book>\n" +
                "      <name>从入门到跑路</name>\n" +
                "      <author>xxxx</author>\n" +
                "      <price>999.9</price>\n" +
                "  </book>");

        String s = stringBuilder.toString();
        try(FileWriter fw = new FileWriter("day11properties-xml-log-thread/xml/aaa/book.xml")) {

            fw.write(s);

        } catch (IOException e) {
            e.printStackTrace();
        }
        try(FileWriter fw = new FileWriter("路径或文件对象") ) {
            fw.write(s );
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
